import React, { Component } from 'react';
import './Right.scss'
import Cate from './Cate'
// 导入通信对象
import context from '../../utils/events';
import { category_subcate } from '../../utils/api'
class Right extends Component {
    constructor(props){
        super(props)
        this.state={
            arr:[]
        }
    }
    componentDidMount(){
        // -提前-  通过通信对象 .on方法对事件进行监听，回调函数的参数得到兄弟组件传的参数
        context.on("derLiverId",(id)=>{
            this.goodsList(id)
        })    
    }
    goodsList(id){
        category_subcate({id}).then((res)=>{
            this.setState({
                arr:res.data.subcate.subcategory
            })
        })
    }
    render() {
        return (
            <div className='right'>
                {
                    this.state.arr.map((item,index)=>{
                      return (
                          <div className='cate' key={index}>
                                <h2>{item.name}</h2>
                                <Cate arr={item.subNavs}></Cate>
                          </div>
                          
                        )
                        
                    })
                }
                
            </div>
        );
    }
}

export default Right;